<?php
class SleekCMS_AdminContentsModule extends Module {
	public function run ($params) {
		$id = isset($params['content_types_id']) ? $params['content_types_id'] : false;

		# 404 if no ID
		if (!$id) {
			return FOF_PAGE;
		}

		# Get the content type
		$contentType = ContentTypesModel::getByID($id);

		# 404 if it doesn't exist
		if (!$contentType) {
			return FOF_PAGE;
		}

		# Insert contents
		if (isset($_POST['add_content'])) {
			$content = new ContentModel(array(
				'title'				=> $_POST['title'], 
				'content_types_id'	=> $_POST['content_types_id']
			));

			$content->save();

			redirect('?added_content'); # TODO: redirect to AdminEditContent
		}

		# Assign template vars
		$this->setData('content_type', $contentType);

		# Now get the contents
		$this->setData('contents', ContentsModel::getByContentTypesID($contentType->getContentTypesID()));
	}
}
